home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 August: Tool Chest / Dev.CD Aug 99 TC.toast / What's New? / Development Kits / Hardware / Mac OS USB DDK v1.3a1 / Examples / PrinterClassDriver / DRVRGlue.a < prev    next >
Encoding:
Text File  |  1999-06-18  |  3.6 KB  |  121 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        DRVRGlue.a
  3. ;
  4. ;    Contains:    DRVR interface
  5. ;    Version:    xxx put version here xxx
  6. ;
  7.  
  8.  
  9.         
  10.     BLANKS    ON
  11.     STRING    ASIS
  12.         
  13.     INCLUDE        'LowMem.a'
  14.     INCLUDE        'Devices.a'
  15. ;
  16. ;    for an explanation of VMimmune and gestalt see AsyncDriverSample 1.0b4
  17. ;
  18. dVMImmuneMask                EQU    $0001
  19. dDriverGestaltEnableMask    EQU    $0004    ; See DriverGestalt.h
  20.  
  21. drvrFlags        EQU    dReadEnableMask +  dWritEnableMask + dCtlEnableMask +  dStatEnableMask
  22. drvrSystemFlags    EQU dNeedLockMask
  23.  
  24. DRVREntry        MAIN    EXPORT
  25.  
  26.                 IMPORT    DRVROpen, DRVRPrime, DRVRControl, DRVRStatus, DRVRClose
  27.  
  28. Header
  29.         dc.w    drvrFlags + drvrSystemFlags
  30.         DC.W    0        ; no run time
  31.         DC.W    0        ; no events
  32.         DC.W    0        ; no menu
  33.  
  34. ; Entry point offset table to the procs: Open, Prime, Control, Status, Close
  35.         DC.W    MyOpen        - DRVREntry  ; open routine
  36.         DC.W    MyPrime        - DRVREntry  ; prime
  37.         DC.W    MyControl    - DRVREntry  ; control
  38.         DC.W    MyStatus    - DRVREntry  ; status
  39.         DC.W    MyClose        - DRVREntry  ; close
  40.  
  41. ; Title
  42. ;        include three pad bytes so we can re-number the driver
  43.         DC.B    14                    ;Length byte
  44.         DC.B    '.USB--Print---'    ;Pad to odd # of chars, so 1st routine
  45.                                     ;  will be word-aligned.
  46.  
  47. ; Push the address of the routine we wish to call and jump to the glue
  48. ; which sets up the parameters and calls the actual driver implementation
  49. MyOpen        PEA        DRVROpen
  50.             bra.s    MyImmGlue
  51. MyPrime        PEA        DRVRPrime
  52.             bra.s    MyIOGlue
  53. MyControl    PEA        DRVRControl
  54.             bra.s    MyCtlGlue
  55. MyStatus    PEA        DRVRStatus
  56.             bra.s    MyIOGlue
  57. MyClose        PEA        DRVRClose
  58.  
  59. ;
  60. ; This glue code is used for Open/Close  - functions that only return immediate results
  61. ;
  62.  
  63. MyImmGlue
  64.             MOVEM.L    A0-A1,-(A7)                ; save params to the routine
  65.             MOVE.L    A1,-(A7)                ; pass the device control entry
  66.             MOVE.L    A0,-(A7)                ; pass the parameter block
  67.             MOVEA.L    $0010(A7),A0            ; address of routine to jump to (C calling conventions)
  68.             JSR        (A0)                    ; do it
  69.             ADDQ    #8,SP                    ; clean up stack
  70.             MOVEM.L    (A7)+,A0-A1                ; restore device parameters
  71.             ADDQ    #4,SP                    ; removed function address 
  72.             BRA.S    ImmedRTS                ; just return
  73.  
  74. MyCtlGlue
  75.             MOVEM.L    A0/A1,-(A7)                ; save params to the routine
  76.             MOVE.L    A1,-(A7)                ; pass the device control entry
  77.             MOVE.L    A0,-(A7)                ; pass the parameter block 
  78.             MOVEA.L    $0010(A7),A0            ; address of routine to jump to (C calling conventions)
  79.             JSR        (A0)                    ; do it
  80.             ADDQ    #8,SP                    ; clean up stack
  81.             MOVEM.L    (A7)+,A0/A1                ; restore device parameters
  82.             ADDQ    #4,SP                    ; removed function address 
  83.             CMPI.W    #killCode,CntrlParam.csCode(A0)
  84.             BNE.B    IOReturn                ; killIO always returns immediately
  85.             BRA.S    ImmedRTS
  86.  
  87. MyIOGlue
  88.             MOVEM.L    A0/A1,-(A7)                ; save params to the routine
  89.             MOVE.L    A1,-(A7)                ; pass the device control entry
  90.             MOVE.L    A0,-(A7)                ; pass the parameter block
  91.             MOVEA.L    $0010(A7),A0            ; address of routine to jump to (C calling conventions)
  92.             JSR        (A0)                    ; do it
  93.             ADDQ    #8,SP                    ; clean up stack
  94.             MOVEM.L    (A7)+,A0/A1                ; restore device parameters
  95.             ADDQ    #4,SP                    ; removed function address 
  96.             
  97. IOReturn    
  98.             MOVE.W    IOParam.ioTrap(A0), D1
  99.             BTST    #noQueueBit,D1            ; test for an async call
  100.             BEQ.S    Queued                    ; if not async, we're done
  101.             
  102.             TST.W    D0                        ; test async return result
  103.             BLE.B    ImmedRTS                ; if error or noErr we should return immediately
  104.             CLR.W    D0                        ; in progress gets converted to noErr
  105. ImmedRTS            
  106.             MOVE.W    D0,IOParam.ioResult(a0)    ; return the immediate result
  107.             RTS
  108.  
  109. Queued        
  110.             TST.W    D0                        ; test async return result
  111.             BLE.B    IODone                    ; if io is complete then we should return through the jIODone vector
  112.             CLR.W    D0                        ; in progress gets converted to noErr
  113.             RTS
  114. IODone            
  115.             SUBQ.W    #4,A7                    ; else get the JIODone vector
  116.             _LMGetJIODone                    ; so we can jump to it.
  117.             RTS
  118.             
  119.             ENDPROC
  120.     END
  121.